package com.cloud.job;

import com.cloud.mapper.SysLogMapper;
import com.cloud.utils.DateUtil;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 操作访问记录的调度器
 * @Author yangyuwei
 * @Date 2023/12/15
 * @Param
 * @Return
 **/
@Slf4j
@Component
public class SysLogArchiveJob {
    @Autowired
    private SysLogMapper sysLogMapper;
    /**
     * 定时归档和清理文件
     */
    @XxlJob("archive")
    public ReturnT<String> archive(String param) {
        Date now = new Date();
        Date beforeDate = DateUtil.addDay(now,-3);
        String renameSuffix = DateUtil.parseDateToStr(now,DateUtil.DATE_FORMAT_YYYYMMDD);
        String deleteSuffix = DateUtil.parseDateToStr(beforeDate,DateUtil.DATE_FORMAT_YYYYMMDD);
        sysLogMapper.archive(renameSuffix,deleteSuffix);
        return ReturnT.SUCCESS;
    }
}
